<!DOCTYPE html>
<html>

<head>

    {include file="Public/header"}
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <style>
        .radio-inline input[type=radio] {
            margin-top: 4px
        }

        .note-editable {
            height: 200px
        }
    </style>
</head>

<body style="color:#333;padding:3px;" class="x_sorll">
<!-- 标题 -->
<div class="page-heade">
    <h2 class="title_color text-center">添加非常规促销申请明细</h2>
</div>
<!-- 标题 -->
<div class="row-margin-top">
    <input type="hidden" name="jxs" value="{:request()->param('jxs')}">
    <form action="" class="form-inline">
        <table class="table-bordered table t_table">

            {if $list.arealat==2}
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">网点<span class="colorRed">*</span>：</label>
                </td>
                <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="net_id" name="net_id" value="{:isset($supply)?$supply.jxs:''}">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-4">
                        <button class="btn btn-primary" id="select_net">选择</button>
                        <button class="btn btn-primary clear_net">清空</button>
                        <a href="javascript:;">选择我的常用网点分组</a>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的网点是：</label></td>
                <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_net">
                        <span class="ren" data-id="{$list.net_id}">{$list.net_title}<span class="close">×</span></span>
                    </div>
                </td>
            </tr>
            {else}
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">您选定的经销商是：</label>
                </td>
                <td colspan="3">
                    {$list.jxs_title}
                </td>
            </tr>
            {/if}


            {if $list.productlat==1}
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">品牌<span class="colorRed">*</span>：</label>
                </td>
                <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="brand" name="brand" value="{:isset($supply)?$supply.jxs:''}">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <button class="btn btn-primary" id="select_brand">选择</button>
                        <button class="btn btn-primary clear_net">清空</button>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的品牌是：</label></td>
                <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_brand">
                        <span class="ren" data-id="{$list.brand}">{$list.brand_title}<span class="close">×</span></span>
                    </div>
                </td>
            </tr>
            {elseif $list.productlat==2}
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">品类<span class="colorRed">*</span>：</label></td>
                <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="category" name="category" value="{:isset($supply)?$supply.jxs:''}">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <button class="btn btn-primary" id="select_category">选择</button>
                        <button class="btn btn-primary clear_net">清空</button>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的品类是：</label></td>
                <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_category">
                        <span class="ren" data-id="{$list.category}">{$list.category_title}<span class="close">×</span></span>
                    </div>
                </td>
            </tr>
            {elseif $list.productlat==3}
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">系列<span class="colorRed">*</span>：</label></td>
                <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="series" name="series" value="{:isset($supply)?$supply.jxs:''}">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <button class="btn btn-primary" id="select_series">选择</button>
                        <button class="btn btn-primary clear_net">清空</button>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的系列是：</label></td>
                <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_series">
                        <span class="ren" data-id="{$list.series}">{$list.series_title}<span class="close">×</span></span>
                    </div>
                </td>
            </tr>
            {elseif $list.productlat==4}
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">SKU<span class="colorRed">*</span>：</label></td>
                <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="sku" name="sku" value="{$list.sku}">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <button class="btn btn-primary" id="select_sku">选择</button>
                        <button class="btn btn-primary clear_net">清空</button>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的SKU是：</label></td>
                <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_sku">
                        <span class="ren" data-id="{$list.sku}">{$list.sku_title}<span class="close">×</span></span>
                    </div>
                </td>
            </tr>
            {else}
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">单品<span class="colorRed">*</span>：</label></td>
                <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="product" name="product" value="{$list.product}">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <button class="btn btn-primary" id="select_product">选择</button>
                        <button class="btn btn-primary clear_net" >清空</button>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的单品是：</label></td>
                <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_product">
                        <span class="ren" data-id="{$list.series}">{$list.product_title}<span class="close">×</span></span>
                    </div>
                </td>
            </tr>
            {/if}

            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">促销执行时间<span class="colorRed">*</span>：</label>
                </td>
                <td>
                    <div class="form-group">
                        <input type="text" id="start" class="form-control layer-date " style="min-width:100px;height: 22px;display: inline-block;" name="" value="{:date('Y-m-d',$list.start)}">
                    </div>
                    <div class="form-group">
                        至
                    </div>
                    <div class="form-group">
                        <input type="text" class="form-control layer-date" style="min-width:100px;height: 22px;display: inline-block;" id="end" name="" value="{:date('Y-m-d',$list.end)}">
                    </div>
                </td>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">负责人<span
                        class="colorRed">*</span>：</label></td>
                <td>
                    <input type="text" class="form-control" style="min-width: 220px;width: 220px" name="head" id="head" value="测试经理" value="{$list.head}">
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">预计核销时间<span class="colorRed">*</span>：</label>
                </td>
                <td colspan="3">
                    <div class="form-group">
                        <input type="text" id="yjverifyTime" class="form-control layer-date "
                               style="min-width:100px;height: 22px;display: inline-block;" name="" onclick="laydate()" value="{:date('Y-m-d',$list.expCanTime)}">
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">总预计销量（元）<span class="helpText">帮</span><span class="colorRed">*</span>：</label>
                </td>
                <td>
                    <div class="form-group">
                        <input type="text" class="form-control" style="min-width:100px;height: 22px;display: inline-block;" name="totalExpectedSales" id="totalExpectedSales" value="{$list.totalExpectedSales}">
                    </div>
                </td>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">总基准销量（元）<span class="helpText">帮</span><span class="colorRed">*</span>：</label>
                </td>
                <td>
                    <div class="form-group">
                        <input type="text" class="form-control" style="min-width:100px;height: 22px;display: inline-block;" name="totalBenchmarkSales" id="totalBenchmarkSales" value="{$list.totalBenchmarkSales}">
                    </div>
                </td>
            </tr>
        </table>
        <table class="table-bordered table t_table" id="table1">
            <tr>
                <th colspan="6" class="text-center font-bold">三级费用科目</th>
            </tr>
            <tr class="info">
                <th class="text-center">费用类型</th>
                <th class="text-center">收款方</th>
                <th class="text-center">未税总额(元)<span class="colorRed">*</span><span class="helpText">帮</span></th>
                <th class="text-center">费用支付方式<span class="colorRed">*</span></th>
                <th class="text-center">费用计入部门<span class="colorRed">*</span></th>
                <th class="text-center">费用计入方案</th>
            </tr>

            <tr class="data">
                <td>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-xs-8">
                                <div class="input-group"  style="display: none;">
                                    <input type="text" placeholder="请输入关键字或空格查询" class="form-control feetype" name="feetype" value="{$list.feetype}">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                                <div class="selectedOnlyOne " >
                                    <span class="inin">{$list.feetype_title}</span>
                                    <span class="close">×</span>
                                </div>
                            </div>
                            <div class="col-xs-4">
                                <button class="btn btn-primary feetree" >选择</button>
                            </div>
                        </div>
                    </div>
                </td>
                <td>
                    <input type="radio" name="payee" value="0" class="payee" {if $list.payee==0}checked{/if}>经销商&nbsp;
                    <input type="radio" name="payee" value="1" class="payee" {if $list.payee==1}checked{/if} >供应商
                    {if $list.payee==1}
                    <div class="payee2">
                        <div class="input-group"  style="display:none;">
                            <input type="text" placeholder="请输入关键字或空格查询" class="form-control suppliers" name="suppliers" value="$list.gys">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                        <div class="selectedOnlyOne " >
                            <span class="inin">{$list.gys_name}</span>
                            <span class="close">×</span>
                        </div>
                    </div>
                    {/if}
                </td>
                <td>
                    <input type="text" name="amount" class="form-control" value="{$list.amount}">
                    {if $list.paymethod==13}<button class="select_buhuo">选择</button>{/if}
                </td>
                <td>
                    <select name="paymethod" class="form-control" data-buhuo='{:addslashes($list.buhuo)}'>
                        <option value="">请选择</option>
                        {volist name="fipay" id="row"}
                        <option value="{$row.id}" {if $list.paymethod==$row.id}selected{/if}>{$row.title}</option>
                        {/volist}
                    </select>
                </td>
                <td>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-xs-8">
                                <div class="input-group"  style="display: none;">
                                    <input type="text" placeholder="请输入关键字或空格查询" class="form-control jrbm" name="jrbm" value="{$list.jrbm}">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                                <div class="selectedOnlyOne " >
                                    <span class="inin">{$list.jrbm_title}</span>
                                    <span class="close">×</span>
                                </div>
                            </div>
                            <div class="col-xs-4">
                                <button class="btn btn-primary select_jrbm" >选择</button>
                            </div>
                        </div>
                    </div>
                </td>
                <td>
                    <select name="project" class="form-control">
                        <option value="">请选择</option>
                        {volist name="fijiru" id="row"}
                        <option value="{$row.id}" {if $list.project==$row.id}selected{/if}>{$row.title}</option>
                        {/volist}
                    </select>
                </td>
            </tr>
        </table>
        <table class="table table-bordered">
            <tr>
                <td class="text-right" row="2">备注</td>
                <td colspan="5">
                    <textarea name="brief" id="brief" rows="2" class="form-control" style="width: 50%">{$list.brief}</textarea><span
                        style="vertical-align: bottom;">(200)</span>
                </td>
            </tr>
        </table>

        <div class="row sub_btn white-bg" style="width:100%;text-align:center;padding: 20px 0">
            <input type="submit" class="btn btn-success" id="save" value="保存并返回" >
            <input type="button" class="btn btn-warning" value="返回" id="fanhui">
        </div>
    </form>
</div>
<!-- 全局js -->
{include file="Public/footer"}
<!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<!--统计代码，可删除-->
<script>
    //日期范围限制
    var start = {
        elem: '#start',
        format: 'YYYY-MM-DD',
//        min: laydate.now(), //设定最小日期为当前日期
//        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };
    var end = {
        elem: '#end',
        format: 'YYYY-MM-DD',
//        min: laydate.now(),
//        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: false,
        choose: function (datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
            $('#yjverifyTime').val(GetDateStr(datas,60))
        }
    };

    function GetDateStr(start,AddDayCount) {
        var dd = new Date(start);
        dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
        var y = dd.getFullYear();
        var m = dd.getMonth()+1;//获取当前月份的日期
        var d = dd.getDate();
        return y+"-"+m+"-"+d;
    }

    laydate(start);
    laydate(end);
    /*我的常用网点分组*/
    $("#addExaDetail").click(function () {
        var str = '<form method="get" class="form-inline" style="margin:10px"><table class="table-bordered table"><tr><td><label class="radio-inline font-bold"><input type="radio" checked name="inlineRadioOptions" id="inlineRadio1" value="option1">根据原申请编号</label><input type="text" class="form-control"/></td></tr><tr><td><label class="radio-inline font-bold"><input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2">根据待核查任务(温馨说明：待核查任务指领导要求核查但还未下发核查任务书的市场(活动)费用申请)</td></tr><tr><td><label class="radio-inline font-bold"><input type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3">自主查找核查明细</td></tr><tr><td class="text-center"><button class="btn btn-success">提交</button></td></tr></table></form>'
        layer.open({
            type: 1,
            title: "添加核查明细",
            skin: 'layui-layer-rim', //加上边框
            area: ['800px', '540px'], //宽高
            content: str
        });
    })

    //返回
    $('#fanhui').click(function () {
        parent.layer.close(parent.layer.getFrameIndex(window.name))
    })

    //关闭多选某一项
    $('body').on('click','.duoxuan .close',function () {
        $(this).closest('.ren').remove()
    })

    //产品网点搜索自动补全
    $("#net_id").bsSuggest({
        url: "{:url('select/netjson2')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        $('#selected_net').html('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')

    });
    //产品品牌搜索自动补全
    $("#brand").bsSuggest({
        url: "{:url('select/brandjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        $('#selected_brand').html('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
    });
    //产品品类搜索自动补全
    $("#category").bsSuggest({
        url: "{:url('select/categoryjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        $('#selected_category').html('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
    });
    //产品系列搜索自动补全
    $("#series").bsSuggest({
        url: "{:url('select/seriesjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        $('#selected_series').html('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
    });
    //产品SKU搜索自动补全
    $("#sku").bsSuggest({
        url: "{:url('select/skujson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        $('#selected_sku').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')

    });
    //产品单品搜索自动补全
    $("#product").bsSuggest({
        url: "{:url('select/productjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        $('#selected_product').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')

    });
    //费用类型搜索自动补全
    $(".feetype").bsSuggest({
        url: "{:url('select/feiyongkemu3json',['esuseway'=>'2'])}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
        $(this).val(keyword.id)

    });
    //费用计入部门搜索自动补全
    $("input[name=jrbm]").bsSuggest({
        url: "{:url('select/jrbmjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
        $(this).val(keyword.id)

    });

    {if $list.payee==1}
    //费用类型搜索自动补全
    $("[name=suppliers]").bsSuggest({
        url: "{:url('select/gyssug')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
        $(this).val(keyword.id)

    });
    {/if}

    //选择经销商或者供应商
    $('input[name=payee]').on('click',function () {
        if($(this).val()==1&&true==$('.payee2').is('div')){
            return false
        }
        if($(this).val()==1){
            $(this).parent().append('<div class="payee2">\n' +
                '                        <div class="input-group" >\n' +
                '                            <input type="text" placeholder="请输入关键字或空格查询" class="form-control suppliers" name="suppliers" value="{:isset($supply)?$supply.jxs:\'\'}">\n' +
                '                            <div class="input-group-btn">\n' +
                '                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">\n' +
                '                                    <span class="caret"></span>\n' +
                '                                </button>\n' +
                '                                <ul class="dropdown-menu dropdown-menu-right" role="menu">\n' +
                '                                </ul>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="selectedOnlyOne " style="display:none;" >\n' +
                '                            <span class="inin">111</span>\n' +
                '                            <span class="close">×</span>\n' +
                '                        </div>\n' +
                '                    </div>')
            //费用类型搜索自动补全
            $("[name=suppliers]").bsSuggest({
                url: "{:url('select/gyssug')}",
                /*effectiveFields: ["userName", "shortAccount"],
                 searchFields: [ "shortAccount"],*/
                effectiveFieldsAlias:{title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onSetSelectValue', function (e, keyword, data) {
                $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
                $(this).val(keyword.id)

            });
        }else{
            $(this).parent().find('.payee2').remove()
        }
    })

    //取消单选
    $('body').on('click','.selectedOnlyOne .close',function () {
        $(this).closest('.selectedOnlyOne').hide().find('.inin').html('')
        $(this).closest('.selectedOnlyOne').prev('.input-group').show().find('input').val('')
    })

    //保存并返回
    $('#save').on('click',function () {
        var data = {}

        //验证网点
        if($('#selected_net').is('div')){
            var lng = $('#selected_net .ren').length;
            if(lng<1){
                swal('','请选择网点','error')
                return false
            }else{
                data.net_id = $('#selected_net .ren').data('id')
            }
        }
        //验证品牌
        if($('#selected_brand').is('div')){
            var lng = $('#selected_brand .ren').length;
            if(lng<1){
                swal('','请选择品牌','error')
                return false
            }else{
                data.brand = $('#selected_brand .ren').data('id')
            }
        }
        //验证品类
        if($('#selected_category').is('div')){
            var lng = $('#selected_category .ren').length;
            if(lng<1){
                swal('','请选择品类','error')
                return false
            }else{
                data.category = $('#selected_category .ren').data('id')
            }
        }
        //验证系列
        if($('#selected_series').is('div')){
            var lng = $('#selected_series .ren').length;
            if(lng<1){
                swal('','请选择系列','error')
                return false
            }else{
                data.series = $('#selected_series .ren').data('id')
            }
        }
        //验证sku
        if($('#selected_sku').is('div')){
            var lng = $('#selected_sku .ren').length;
            if(lng<1){
                swal('','请选择sku','error')
                return false
            }else{
                data.sku = $('#selected_sku .ren').data('id')
            }
        }
        //验证单品
        if($('#selected_product').is('div')){
            var lng = $('#selected_product .ren').length;
            if(lng<1){
                swal('','请选择单品','error')
                return false
            }else{
                data.product = $('#selected_product .ren').data('id')
            }
        }

        //验证时间
        var start = $('#start').val()
        if(start==''){
            swal('','请填写促销执行时间开始日期','error')
            return false
        }else{
            data.start = start
        }
        var end = $('#end').val()
        if(end==''){
            swal('','请填写促销执行时间结束日期','error')
            return false
        }else{
            data.end = end
        }
        var head = $('#head').val()
        if(head==''){
            swal('','请填写负责人','error')
            return false
        }else{
            data.head = head
        }
        var yjverifyTime = $('#yjverifyTime').val()
        if(yjverifyTime==''){
            swal('','请填写预计核销时间','error')
            return false
        }else{
            data.yjverifyTime = yjverifyTime
        }
        var totalExpectedSales = $('#totalExpectedSales').val()
        if(totalExpectedSales==''){
            swal('','请填写总预计销量','error')
            return false
        }else{
            data.totalExpectedSales = totalExpectedSales
        }
        var totalBenchmarkSales = $('#totalBenchmarkSales').val()
        if(totalBenchmarkSales==''){
            swal('','请填写总基准销量','error')
            return false
        }else{
            data.totalBenchmarkSales = totalBenchmarkSales
        }

        var list = [],success=true
        $('#table1 tr.data').each(function (i,o) {
            var feetype = $(this).find('input[name=feetype]').val()
            var payee = $(this).find('input.payee:checked').val()
            var jxs = $(this).find('input[name=jxs]').val()
            var amount = $(this).find('input[name=amount]').val()
            var paymethod = $(this).find('[name=paymethod]').val()
            var buhuo = $(this).find('[name=paymethod]').data('buhuo')
            var jrbm = $(this).find('input[name=jrbm]').val()
            var project = $(this).find('[name=project]').val()
            payee = payee=='1'?jxs:0;

            if(feetype==''){
                swal('','请选择费用类型','error')
                success = false
                return false
            }
            if(payee===''){
                swal('','请选择收货方','error')
                success = false
                return false
            }
            if(amount==''){
                swal('','请填写未税总额','error')
                success = false
                return false
            }
            if(paymethod==''){
                swal('','请选择费用支付方式','error')
                success = false
                return false
            }
            if(jrbm==''){
                swal('','请选择费用计入部门','error')
                success = false
                return false
            }
            if(project==''){
                swal('','请选择费用计入方案','error')
                success = false
                return false
            }
            list.push({
                feetype:feetype,
                payee:payee,
                amount:amount,
                paymethod:paymethod,
                buhuo:buhuo,
                jrbm:jrbm,
                project:project
            })
        })

        if(success==false){
            return false
        }


        var brief = $('#brief').val()
        data.brief = brief
        data.jxs_id = parent.$('#remainMan').val()
        data.jxs = "{$list.jxs_title}"
        data.arealat = "{$list.arealat}"
        data.productlat = "{$list.productlat}"

        data = $.extend(data,list[0])
//        data = JSON.stringify(data)
//        console.log(data)
        $.post('',data,function (data) {
            if(data.success){
                swal({
                    title: data.msg,
                    type: "success",
                }, function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name))
                })
            }else{
                swal('',data.msg,'error')
            }
        },'json')
        return false
    })
</script>
<script>
    $(function () {

        //清空网点或产品
        $('.clear_net').on('click',function () {
            $(this).closest('tr').next('tr').find('.duoxuan').html('')
            return false
        })

        //弹出选择网点框
        $('#select_net').on('click',function () {
            var index = layer.getFrameIndex(window.name)
            layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:'{:url("selectNet")}?index='+index+'&keyword={:request()->get("jxs_id")}'
            })
            return  false
        })
        //弹出选择品牌框
        $('#select_brand').on('click',function () {
            var index = layer.getFrameIndex(window.name)
            layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:'{:url("selectBrands")}?index='+index
            })
            return  false
        })

        //弹出选择品类框
        $('#select_category').on('click',function () {
            var index = layer.getFrameIndex(window.name)
            layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:'{:url("selectCategory")}?index='+index
            })
            return  false
        })

        //弹出选择系列框
        $('#select_series').on('click',function () {
            var index = layer.getFrameIndex(window.name)
            layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:'{:url("selectSeries")}?index='+index
            })
            return  false
        })

        //弹出选择sku系列框
        $('#select_sku').on('click',function () {
            var index = layer.getFrameIndex(window.name)
            layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:'{:url("selectSKU")}?index='+index
            })
            return  false
        })

        //弹出选择我的费用科目树
        $('body').on('click','.feetree',function () {
            var _this = this
            layer.open({
                type:2,
                area:['60%','60%'],
                title:'费用科目树',
                maxmin:true,
                content:'{:url("selectFee")}',
                btn:'确定',
                yes:function (i,o) {
                    var id = $(o).find('iframe').contents().find('#renyuan').val()
                    var name = $(o).find('iframe').contents().find('#renyuanname').val()
                    if(id){
                        $(_this).closest('div').prev('div').find('.input-group').hide().find('.feetype').val(id)
                        $(_this).closest('div').prev('div').find('.selectedOnlyOne').show().find('.inin').html(name)
                    }
                    layer.close(i)
                }
            })
            return  false
        })
        //弹出选择我的费用计入部门树
        $('body').on('click','.select_jrbm',function () {
            var _this = this
            layer.open({
                type:2,
                area:['60%','60%'],
                title:'费用计入部门树',
                maxmin:true,
                content:'{:url("selectJrbm")}',
                btn:'确定',
                btnAlign:'c',
                yes:function (i,o) {

                    var id = $(o).find('iframe').contents().find('#renyuan').val()
                    var name = $(o).find('iframe').contents().find('#renyuanname').val()
                    if(id){
                        $(_this).closest('div').prev('div').find('.input-group').hide().find('.feetype').val(id)
                        $(_this).closest('div').prev('div').find('.selectedOnlyOne').show().find('.inin').html(name)
                    }
                    layer.close(i)
                }
            })
            return  false
        })

        //选择费用支付方式为补货时候
        $('body').on('change','select[name=paymethod]',function () {
            var _this = this
            if(parseInt($(this).val())==13){
                swal({
                    title: "您选择了补货的支付方式，请确认是否添加补货的明细",
                    type: "warning",
                    showCancelButton: true,
//                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    closeOnConfirm: false
                }, function (is) {
                    $(_this).closest('tr').find('[name=amount]').closest('td').append('<button class="select_buhuo">选择</button>')
                    if(is){
                        layer.open({
                            type:2,
                            area:['60%','60%'],
                            title:'补货明细',
                            maxmin:true,
                            content:'{:url("addbhlist")}',
                            btn:'确定',
                            btnAlign:'c',
                            yes:function (i,o) {

                                var table1 = $(o).find('iframe').contents().find('#table1')
                                var data = []
                                if(table1.children('tbody').children('tr').length==0){
                                    swal('请添加物料/物料再保存','','error')
                                    return false
                                }

                                bool = true
                                table1.children('tbody').children('tr').each(function (i,o) {
                                    var wy = $(o).find('.wy:checked').val()
                                    var product = $(o).find('[name=product]').val()
                                    var product_title = $(o).find('.selectedOnlyOne .inin').text()
                                    if(product==''){
                                        swal('请选择样品或物料','','error')
                                        bool = false
                                        return false
                                    }
                                    var num = $(o).find('[name=num]').val()
                                    if(num==''){
                                        swal('请填写数量','','error')
                                        bool = false
                                        return false
                                    }
                                    var unit = $(o).find('.unit').text()
                                    var price = $(o).find('.price').text()
                                    var total = $(o).find('.total').text()
                                    data.push({wy:wy,product:product,product_title:product_title,num:num,unit:unit,price:price,total:total})
                                })

                                if(bool == false){
                                    return false
                                }

                                //合计
                                var heji = table1.find('#heji').text()

                                //字符串化并存储到select对象上
                                $(_this).data('buhuo',JSON.stringify(data))
                                //提交

                                $(_this).closest('tr').find('input[name=amount]').val(heji)

                                layer.close(i)
                            },
                            success:function (o,i) {
                                var buhuo =  $(_this).data('buhuo')
                                console.log(buhuo)
                                buhuo = JSON.parse(buhuo)
                                var table1 = $(o).find('iframe').contents().find('#table1')

                                for(var i = 0;i < buhuo.length;i++){
                                    var checked = buhuo[i].wy==0?'checked':''
                                    var checked2 = buhuo[i].wy==1?'checked':''
                                    table1.children('tbody').append('<tr>\n' +
                                        '            <td style="width:40%;">\n' +
                                        '               <div class="col-xs-5">' +
                                        '                <label for=""><input type="radio" name="'+name+'" class="wy" value="0" '+checked+'>样品</label>\n' +
                                        '                <label for=""><input type="radio" name="'+name+'" class="wy" value="1" '+checked2+'>物料</label>' +
                                        '               </div>\n' +
                                        '               <div class="col-xs-7">'+
                                        '                <div class="input-group show1" style="display:none">\n' +
                                        '                    <input name="stuff" type="text" placeholder="请输入关键字或空格查询"\n' +
                                        '                           class="input12 form-control sample" value="">\n' +
                                        '                    <div class="input-group-btn">\n' +
                                        '                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">\n' +
                                        '                            <span class="caret"></span>\n' +
                                        '                        </button>\n' +
                                        '                        <ul class="dropdown-menu dropdown-menu-right" role="menu">\n' +
                                        '                        </ul>\n' +
                                        '                    </div>\n' +
                                        '                </div>\n' +
                                        '                <div class="input-group show2 col-xs-2" style="display: none;">\n' +
                                        '                    <input name="stuff"  type="text" placeholder="请输入关键字或空格查询"\n' +
                                        '                           class="input12 form-control material" value="">\n' +
                                        '                    <div class="input-group-btn">\n' +
                                        '                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">\n' +
                                        '                            <span class="caret"></span>\n' +
                                        '                        </button>\n' +
                                        '                        <ul class="dropdown-menu dropdown-menu-right" role="menu">\n' +
                                        '                        </ul>\n' +
                                        '                    </div>\n' +
                                        '                </div>' +
                                        '                <div class="selectedOnlyOne">\n' +
                                        '                    <input type="hidden" name="product" value="'+buhuo[i].product+'">\n' +
                                        '                    <span class="inin">'+buhuo[i].product_title+'</span>\n' +
                                        '                    <span class="close">×</span>\n' +
                                        '                </div>\n' +
                                        '           </div>\n' +

                                        '            </td>\n' +
                                        '            <td>\n' +
                                        '                <input type="text" name="num" value="'+buhuo[i].num+'">\n' +
                                        '            </td>\n' +
                                        '            <td>\n' +
                                        '                <span class="unit">'+buhuo[i].unit+'</span>\n' +
                                        '            </td>\n' +
                                        '            <td>\n' +
                                        '                <span class="price">'+buhuo[i].price+'</span>\n' +
                                        '            </td>\n' +
                                        '            <td>\n' +
                                        '                <span class="total">'+buhuo[i].total+'</span>\n' +
                                        '            </td>\n' +
                                        '            <td>\n' +
                                        '                <button class="delete">删除</button>\n' +
                                        '            </td>\n' +
                                        '        </tr>');
                                    var heji = $(_this).closest('tr').find('input[name=amount]').val()
                                    table1.find('#heji').html(heji)
                                }

                            }
                        })
                        swal.close()
                    }else{

                    }

                });
            }else{
                $(_this).closest('tr').find('.select_buhuo').remove()
            }
        })

        //选择补货
        $('body').on('click','.select_buhuo',function () {
            var _paymethod = $(this).closest('tr').find('select[name=paymethod]')
            layer.open({
                type:2,
                area:['60%','60%'],
                title:'补货明细',
                maxmin:true,
                content:'{:url("addbhlist")}',
                btn:'确定',
                btnAlign:'c',
                yes:function (i,o) {

                    var table1 = $(o).find('iframe').contents().find('#table1')
                    var data = []
                    if(table1.children('tbody').children('tr').length==0){
                        swal('请添加物料/物料再保存','','error')
                        return false
                    }
                    console.log(table1)
                    var bool = true
                    table1.children('tbody').children('tr').each(function (i,o) {
                        var wy = $(o).find('.wy:checked').val()
                        var product = $(o).find('[name=product]').val()
                        var product_title = $(o).find('.selectedOnlyOne .inin').text()
                        if(product==''){
                            swal('请选择样品或物料','','error')
                            bool = false
                            return false
                        }
                        var num = $(o).find('[name=num]').val()
                        if(num==''){
                            swal('请填写数量','','error')
                            bool = false
                            return false
                        }
                        var unit = $(o).find('.unit').text()
                        var price = $(o).find('.price').text()
                        var total = $(o).find('.total').text()
                        data.push({wy:wy,product:product,product_title:product_title,num:num,unit:unit,price:price,total:total})
                    })

                    if(bool == false){
                        return false
                    }

                    //合计
                    var heji = table1.find('#heji').text()

                    //字符串化并存储到select对象上
                    _paymethod.data('buhuo',JSON.stringify(data))
                    //提交

                    _paymethod.closest('tr').find('input[name=amount]').val(heji)

                    layer.close(i)
                },
                success:function (o,i) {
                    var buhuo =  _paymethod.data('buhuo')
                    //alert(typeof buhuo)
                    buhuo = buhuo.replace(/\\/g,"")
                    buhuo = JSON.parse(buhuo)

                    var table1 = $(o).find('iframe').contents().find('#table1')

                    for(var i = 0;i < buhuo.length;i++){
                        var checked = buhuo[i].wy==0?'checked':''
                        var checked2 = buhuo[i].wy==1?'checked':''
                        table1.children('tbody').append('<tr>\n' +
                            '            <td style="width:40%;">\n' +
                            '               <div class="col-xs-5">' +
                            '                <label for=""><input type="radio" name="'+name+'" class="wy" value="0" '+checked+'>样品</label>\n' +
                            '                <label for=""><input type="radio" name="'+name+'" class="wy" value="1" '+checked2+'>物料</label>' +
                            '               </div>\n' +
                            '               <div class="col-xs-7">'+
                            '                <div class="input-group show1" style="display:none">\n' +
                            '                    <input name="stuff" type="text" placeholder="请输入关键字或空格查询"\n' +
                            '                           class="input12 form-control sample" value="">\n' +
                            '                    <div class="input-group-btn">\n' +
                            '                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">\n' +
                            '                            <span class="caret"></span>\n' +
                            '                        </button>\n' +
                            '                        <ul class="dropdown-menu dropdown-menu-right" role="menu">\n' +
                            '                        </ul>\n' +
                            '                    </div>\n' +
                            '                </div>\n' +
                            '                <div class="input-group show2 col-xs-2" style="display: none;">\n' +
                            '                    <input name="stuff"  type="text" placeholder="请输入关键字或空格查询"\n' +
                            '                           class="input12 form-control material" value="">\n' +
                            '                    <div class="input-group-btn">\n' +
                            '                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">\n' +
                            '                            <span class="caret"></span>\n' +
                            '                        </button>\n' +
                            '                        <ul class="dropdown-menu dropdown-menu-right" role="menu">\n' +
                            '                        </ul>\n' +
                            '                    </div>\n' +
                            '                </div>' +
                            '                <div class="selectedOnlyOne">\n' +
                            '                    <input type="hidden" name="product" value="'+buhuo[i].product+'">\n' +
                            '                    <span class="inin">'+buhuo[i].product_title+'</span>\n' +
                            '                    <span class="close">×</span>\n' +
                            '                </div>\n' +
                            '           </div>\n' +

                            '            </td>\n' +
                            '            <td>\n' +
                            '                <input type="text" name="num" value="'+buhuo[i].num+'">\n' +
                            '            </td>\n' +
                            '            <td>\n' +
                            '                <span class="unit">'+buhuo[i].unit+'</span>\n' +
                            '            </td>\n' +
                            '            <td>\n' +
                            '                <span class="price">'+buhuo[i].price+'</span>\n' +
                            '            </td>\n' +
                            '            <td>\n' +
                            '                <span class="total">'+buhuo[i].total+'</span>\n' +
                            '            </td>\n' +
                            '            <td>\n' +
                            '                <button class="delete">删除</button>\n' +
                            '            </td>\n' +
                            '        </tr>');
                        var heji = _paymethod.closest('tr').find('input[name=amount]').val()
                        table1.find('#heji').html(heji)
                    }


                    //样品搜索补全
                    $(o).find('iframe').contents().find(".sample").bsSuggest({
                        url: "{:url('select/samplejson')}",
                        effectiveFieldsAlias: {title: "名称"},
                        ignorecase: true,
                        showHeader: true,
                        showBtn: false,     //不显示下拉按钮
                        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                        idField: "id",
                        keyField: "title",
                        clearable: true
                    }).on('onSetSelectValue', function (e, keyword, data) {
                        $(this).closest('.input-group').hide()
                        $(this).val('')
                        $(this).closest('td').find('.inin').html(keyword.key)
                        $(this).closest('td').find('[name=product]').val(keyword.id)
                        $(this).closest('td').find('.selectedOnlyOne').show()

                    })

                    //物料搜索补全
                    $(o).find('iframe').contents().find(".material").bsSuggest({
                        url: "{:url('select/materialjson')}",
                        effectiveFieldsAlias: {title: "名称"},
                        ignorecase: true,
                        showHeader: true,
                        showBtn: false,     //不显示下拉按钮
                        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                        idField: "id",
                        keyField: "title",
                        clearable: true
                    }).on('onDataRequestSuccess', function (e, result) {
                        $(this).closest('tr').data('rs',JSON.stringify(result.value))
                        console.log('onDataRequestSuccess: ', result);
                    }).on('onSetSelectValue', function (e, keyword, data) {
                        $(this).closest('.input-group').hide()
                        $(this).val('')
                        $(this).closest('td').find('.inin').html(keyword.key)
                        $(this).closest('td').find('[name=product]').val(keyword.id)
                        $(this).closest('td').find('.selectedOnlyOne').show()

                        var rs = $(this).closest('tr').data('rs')
                        rs = JSON.parse(rs)
                        for(var i=0;i<rs.length;i++){
                            if(rs[i].id==keyword.id){
                                $(this).closest('tr').find('.unit').html(rs[i].unit)
                                $(this).closest('tr').find('.price').html(rs[i].factory)
                            }
                        }
                    })
                }
            })
            return false
        })
    })
</script>
</body>

</html>
